package com.example.designer.command;

import com.example.designer.command.impl.Command;
import com.example.designer.command.inte.NoCommand;

/**
 * 命令请求者
 */
public class RequestController {

    private Command onCommand;
    private Command offCommand;
    private Command undoCommand;

    public RequestController() {
    }

    //设置命令执行者对象
    public void setCommand(Command onCommand,Command offCommand) {
        this.onCommand = onCommand;
        this.offCommand = offCommand;
        this.undoCommand = new NoCommand();
    }

    //执行命令
    public void onButtom() {
        onCommand.execute();
        undoCommand = onCommand;
    }
    public void offButtom() {
        offCommand.execute();
        undoCommand = offCommand;
    }

    //撤销命令
    public void undo() {
        undoCommand.undo();
    }
}
